import { useState } from "react"
// 在函数组件中,复用组件的思路就是使用自定义的hook

// 类组件中,复用组件的逻辑使用HOC高阶组件

// 自定义hook的名字约定以use开头 



type method = () => void
// 泛型函数 约束自定义hook
type IuseCounter = <T>(param: T) => [T, { inc: method; dec: method }]

const useCounter: IuseCounter = (initialState: any) => {

    let [count, setCount] = useState(initialState)

    let inc = () => {
        setCount(count + 1)
    }

    let dec = () => {
        setCount(count - 1)
    }

    return [count, { inc, dec }]
}

export default useCounter


// let [a,setxx] = useState(0)